<?php
    include_once("../action/checkAuthenticationAction.php");
    include_once("../service/categoryService.php");
    include_once("../util/constant.php");
    
    include_once("../util/authUtil.php");
    $perm_array = $_SESSION["permissions"];
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>Dashboard</title>
	<?php include("import-css.php");?>	
</head>
<body>
	<?php include("header.php");?>
    
    <div class="container-fluid">
		<div class="row-fluid">
            <!--Menu-->
            <?php include("menu.php");?>
            <!--Content-->
            <div class="box span10 offset2">
    					<div class="box-header well" data-original-title>
                            <?php
                                
                                if(!authUtil(array("edit optionitem","view optionitem"),$perm_array,false)){
                                    echo "<script>window.location.href='../admin/index.php';</script>";
                                }
                            ?>
    						<div class="box-icon">
    							<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
    						</div>
    					</div>
    					<div class="box-content">
    						<table class="table table-striped table-bordered bootstrap-datatable datatable">
    						  <thead>
    							  <tr>
    								  <th>Thuộc tính</th>
    								  <th>Thuộc nhóm sản phẩm</th>
    								  <th>Chức năng</th>
    							  </tr>
    						  </thead>   
    						  <tbody>
                                <?php
                                $options = getAllOption();
                                    while($option = mysql_fetch_array($options)){
                                ?>
                                        <tr>
                                            <td><?php echo $option['OPP_NAME']; ?></td>
                                            <td class="center">
                                                <?php
                                                    $categories = getCategoryOfOption($option['OPP_ID']);
                                                    while($category = mysql_fetch_array($categories)){
                                                ?>
                                                    [<?php echo $category["CAT_NAME"]; ?>]
                                                <?php
                                                    }
                                                ?>
                                            </td>
                                            <td class="center">
                                                <?php
                                                    $require_perm = array("edit optionitem","create optionitem");
                                                    if(authUtil($require_perm,$perm_array,false)){
                                                ?>
                                                        <a class="btn btn-info" href="./optionitemdetail.php?action=<?php echo EDIT_ACTION; ?>&id=<?php echo $option['OPP_ID']; ?>">
                                                            <i class="icon-edit icon-white"></i>  
                                                            Cập nhật
                                                        </a>
                                                <?php
                                                    }
												?>
												<?php
                                                    $require_perm = array("delete optionitem");
                                                    if(authUtil($require_perm,$perm_array,true)){
													   if(isOptionDeletetable($option["OPP_ID"])){
												?>
                                                        <a class="btn btn-danger" href="../action/deleteOptionItem.php?id=<?php echo $option["OPP_ID"]; ?>">
                                                            <i class="icon-trash icon-white"></i> 
                                                            Xóa
                                                        </a>
												<?php
													   }
                                                    }
												?>
                                            </td>
                                        </tr>
                                <?php
                                    }
                                ?>
    						  </tbody>
    					  </table>            
                        </div>
            </div><!--/span-->
        </div>
    </div>

    <?php include("footer.php");?>
		
	</div><!--/.fluid-container-->

	<?php include("import-js.php");?>	
    
</body>
</html>
